package com.sanfeng.smbms.controller;

import com.sanfeng.smbms.common.utils.PageUtils;
import com.sanfeng.smbms.common.utils.R;
import com.sanfeng.smbms.entity.ProductEntity;
import com.sanfeng.smbms.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author Nelson
 * @email Nelson@gmail.com
 * 产品信息
 * @date 2022-07-03 17:23:57
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = productService.queryPage(params);
        return R.ok().put("page", page);
    }
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    public R listAll() {
        List<ProductEntity> productEntities = productService.queryPage();
        return R.ok().put("page", productEntities);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{productid}")
    public R info(@PathVariable("productid") Integer productid) {
        ProductEntity product = productService.getById(productid);
        return R.ok().put("product", product);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public R save(@RequestBody ProductEntity product) {
        productService.save(product);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ProductEntity product) {
        productService.updateById(product);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody List productids) {
        productService.removeByIds(productids);
        return R.ok();
    }

}
